package com.atguigu.gmall.product;

import org.csource.fastdfs.*;
import org.springframework.util.ClassUtils;

import java.net.URL;

/**
 * @author 李旭
 * @date 2022/1/4 10:08
 * @Description:
 */
public class FileUploadDemo {

    public static void main(String[] args) throws Exception{
    /*    D:\IdeaProjects\gmall-210712\gmall-parent\service\
        service-product\src\main\resources\fdfs_client.conf*/
        //String path1 = FileUploadDemo.class.getClassLoader().getResource("fdfs_client.conf").getPath();
        String url = ClassUtils.getDefaultClassLoader().
                getResource("fdfs_client.conf").getPath();
        //0:加载配置文件  IO流读取配置文件  IO绝对路径 不认识相对路径
        ClientGlobal.init(url);

        //1:创建跟踪器
        TrackerClient trackerClient  = new TrackerClient();
        //2:连接跟踪器
        TrackerServer trackerServer = trackerClient.getConnection();
        //3: 创建存储节点客户端
        StorageServer storageServer = null;//扩展 功能
        StorageClient1 storageClient1 = new StorageClient1(trackerServer,storageServer);
        //4:上传文件
        String path = storageClient1.upload_file1(
                "D:\\尚品汇商城\\资料\\图片\\小米Redmi K30\\8bda56c1434e9380.jpg",
                "jpg", null);
        System.out.println(path);
        //      http://192.168.200.133:8080/group1/M00/00/00/wKjIhWHTsQWAPu4IAAKNYXoWRRA135.jpg
    }
}
